package learnjava.interview;

import java.util.*;

public class Huawei {

    public static void main(String[] args) {

        Integer[] nums = {1,2,3,4,5,6,7,8,9,10};
        ArrayList<int[]> all = maxRadio(nums,5);
        for (int[] ints : all) {
            System.out.println(ints[0]+","+ints[1]);
        }
    }

    public int maxRadio(int[] works, int[] ster){
        return 0;
    }

    public static ArrayList<int[]> maxRadio(Integer[] nums, int avg){
        HashMap<Integer, ArrayList<Integer>> hashMap = new HashMap<>();
        Arrays.sort(nums,(o1,o2)->o2-o1);
        ArrayList<int[]> all = new ArrayList<>();
        for (int num : nums) {
            int res = Math.floorMod(num,avg);
            int diff = (avg - res)%avg; //匹配的桶，有可能res=0
            ArrayList<Integer> pairs = hashMap.get(diff);
            if(pairs!=null&&pairs.size()>0){ //可以匹配
                all.add(new int[]{num,pairs.get(0)});
                pairs.remove(0);
            }else {
                ArrayList<Integer> cur = hashMap.getOrDefault(res,new ArrayList<>());
                cur.add(num);
                hashMap.put(res,cur);
            }
        }
        //检查hashMap各桶空否
        for (Integer integer : hashMap.keySet()) {
            if(hashMap.get(integer).size()!=0) return null;
        }
        //检查通过,排序
        all.sort(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Math.max(o2[0],o2[1])-Math.max(o1[0],o1[1]);
            }
        });
        return all;
    }

    public static ArrayList<int[]> t3(int[][] constoms){
        //计算顾客价值
        int n = constoms.length;
        int[] count = {100,90,80,70};
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            int station = constoms[i][1]-constoms[i][0];
            values[i] = station*count[station-1];
        }
        //构建互斥关系
        int[][] mutex = new int[n][n];
        for (int i = 0; i < n; i++) {
            int[] ii = constoms[i];
            for (int j = i+1; j < n; j++) {
                int[] jj = constoms[j];
                //检查重合
                if(!(ii[1]<=jj[0]||ii[0]>=jj[1])){
                    mutex[i][j] = 1;
                    mutex[j][i] = 1;
                }
            }
        }
        //开始动态规划,dp[i]代表到第i个顾客可获得的最大收益
        int[] dp = new int[n+1];
        for (int i = 0; i <= n ; i++) {
//            dp[]
        }
        return new ArrayList<>();
    }
}
